//
// Source code recreated from a .class file by IntelliJ IDEA
// (powered by Fernflower decompiler)
//

package net.mingsoft.basic.util;

import cn.hutool.core.collection.CollectionUtil;
import cn.hutool.core.io.file.FileNameUtil;
import cn.hutool.core.lang.Filter;
import cn.hutool.core.lang.mutable.MutablePair;
import cn.hutool.http.HttpUtil;
import cn.hutool.json.JSONUtil;
import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.LineNumberReader;
import java.io.PrintWriter;
import java.lang.reflect.Constructor;
import java.lang.reflect.Field;
import java.net.InetAddress;
import java.net.UnknownHostException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Enumeration;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.ResourceBundle;
import javax.servlet.ServletContext;
import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import net.mingsoft.base.constant.e.BaseCookieEnum;
import net.mingsoft.base.constant.e.BaseEnum;
import net.mingsoft.base.constant.e.BaseSessionEnum;
import net.mingsoft.basic.biz.IAppBiz;
import net.mingsoft.basic.entity.AppEntity;
import net.mingsoft.basic.entity.ManagerEntity;
import net.mingsoft.basic.exception.BusinessException;
import net.mingsoft.config.MSProperties;
import org.apache.commons.lang3.ArrayUtils;
import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang3.math.NumberUtils;
import org.apache.shiro.SecurityUtils;
import org.apache.shiro.subject.Subject;
import org.apache.tika.exception.ZeroByteFileException;
import org.apache.tika.metadata.Metadata;
import org.apache.tika.parser.AutoDetectParser;
import org.apache.tika.parser.ParseContext;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.core.env.Environment;
import org.springframework.util.ClassUtils;
import org.xml.sax.helpers.DefaultHandler;

public class BasicUtil {
    protected static final Logger LOG = LoggerFactory.getLogger(BasicUtil.class);
    private static String[] mobileGateWayHeaders = new String[]{"ZXWAP", "chinamobile.com", "monternet.com", "infoX", "XMS 724Solutions HTG", "wap.lizongbo.com", "Bytemobile"};
    private static String[] pcHeaders = new String[]{"Windows 98", "Windows ME", "Windows 2000", "Windows XP", "Windows NT", "Ubuntu"};
    private static String[] mobileUserAgents = new String[]{"Nokia", "SAMSUNG", "MIDP-2", "CLDC1.1", "SymbianOS", "MAUI", "UNTRUSTED/1.0", "Windows CE", "iPhone", "iPad", "Android", "BlackBerry", "UCWEB", "ucweb", "BREW", "J2ME", "YULONG", "YuLong", "COOLPAD", "TIANYU", "TY-", "K-Touch", "Haier", "DOPOD", "Lenovo", "LENOVO", "HUAQIN", "AIGO-", "CTC/1.0", "CTC/2.0", "CMCC", "DAXIAN", "MOT-", "SonyEricsson", "GIONEE", "HTC", "ZTE", "HUAWEI", "webOS", "GoBrowser", "IEMobile", "WAP2.0"};
    /** @deprecated */
    @Deprecated
    private static final String PAGE_NO = "pageNo";
    private static final String PAGE_NUMBER = "pageNumber";
    private static final String PAGE_SIZE = "pageSize";
    private static final String PAGE = "page";
    private static final String IDS = "ids";

    public BasicUtil() {
    }

    public static AppEntity getApp() {
        AppEntity app = getWebsiteApp();
        if (app == null) {
            AppEntity _app = null;
            IAppBiz appBiz = (IAppBiz)SpringUtil.getBean(IAppBiz.class);
            if (SpringUtil.getRequest() != null) {
                if (MapCacheUtil.get(getDomain()) != null) {
                    _app = (AppEntity)MapCacheUtil.get(getDomain());
                } else {
                    _app = (AppEntity)appBiz.getOne(new LambdaQueryWrapper<AppEntity>().like(AppEntity::getAppUrl, getDomain()), false);
                    if (_app == null) {
                        MapCacheUtil.put(getDomain(), new AppEntity());
                    } else {
                        MapCacheUtil.put(getDomain(), _app);
                    }
                }
            }

            if (_app == null || StringUtils.isBlank(_app.getId())) {
                if (MapCacheUtil.get("firstApp") != null) {
                    _app = (AppEntity)MapCacheUtil.get("firstApp");
                } else {
                    _app = appBiz.getFirstApp();
                    MapCacheUtil.put("firstApp", _app);
                }
            }

            if (_app != null) {
                if (SpringUtil.getRequest() != null) {
                    _app.setAppUrl(getUrl());
                }

                return _app;
            }
        }

        return app;
    }

    public static AppEntity getWebsiteApp() {
        return (AppEntity)getSession("app");
    }

    public static String getContextPath() {
        Environment environment = (Environment)SpringUtil.getBean(Environment.class);
        return (String)environment.getProperty("server.servlet.context-path", String.class, "/");
    }

    public static String getUrl(String server) {
        HttpServletRequest request = SpringUtil.getRequest();
        if (getWebsiteApp() != null) {
            LOG.debug("BasicUtil.getWebsiteApp() != null is true");
            return getWebsiteApp().getAppUrl();
        } else {
            Environment environment = (Environment)SpringUtil.getBean(Environment.class);
            String scheme = (String)environment.getProperty("ms.scheme", String.class, "http");
            int port = (Integer)environment.getProperty("server.port", Integer.class, 8080);
            String path = (String)environment.getProperty("server.servlet.context-path", String.class, "/");
            if (request == null) {
                return null;
            } else {
                String serverName = request.getServerName();
                if (!StringUtil.isIP(serverName)) {
                    server = serverName;
                }

                String basePath = scheme + "://" + (String)Optional.ofNullable(server).orElse(request.getServerName());
                int _port = request.getServerPort();
                if (_port == 80 || _port != port) {
                    port = _port;
                }

                if (port != 80 && port != 443) {
                    basePath = basePath + ":" + port;
                    if (!"/".equals(path)) {
                        basePath = basePath + path + "/";
                    } else {
                        basePath = basePath + "/";
                    }
                } else if (!"/".equals(path)) {
                    basePath = basePath + path + "/";
                } else {
                    basePath = basePath + "/";
                }

                LOG.debug("server:{},basePath:{}", server, basePath);
                return basePath;
            }
        }
    }

    public static String getUrl() {
        return getUrl((String)null);
    }

    public String getMACAddress(String ip) {
        String str = "";
        String macAddress = "";

        try {
            Process p = Runtime.getRuntime().exec("nbtstat -A " + ip);
            InputStreamReader ir = new InputStreamReader(p.getInputStream());
            LineNumberReader input = new LineNumberReader(ir);

            for(int i = 1; i < 100; ++i) {
                str = input.readLine();
                if (str != null && str.indexOf("MAC Address") > 1) {
                    macAddress = str.substring(str.indexOf("MAC Address") + 14, str.length());
                    break;
                }
            }
        } catch (IOException var8) {
            var8.printStackTrace(System.out);
        }

        return macAddress;
    }

    public static String getIp() {
        HttpServletRequest request = SpringUtil.getRequest();
        String ipAddress = null;
        LOG.debug("headers:{}", JSONUtil.toJsonStr(request.getHeaderNames()));
        ipAddress = request.getHeader("X-Forwarded-For");
        if (ipAddress == null || ipAddress.length() == 0 || "unknown".equalsIgnoreCase(ipAddress)) {
            ipAddress = request.getHeader("Proxy-Client-IP");
        }

        if (ipAddress == null || ipAddress.length() == 0 || "unknown".equalsIgnoreCase(ipAddress)) {
            ipAddress = request.getHeader("WL-Proxy-Client-IP");
        }

        if (ipAddress == null || ipAddress.length() == 0 || "unknown".equalsIgnoreCase(ipAddress)) {
            ipAddress = request.getRemoteAddr();
            if (ipAddress.equals("127.0.0.1")) {
                InetAddress inet = null;

                try {
                    inet = InetAddress.getLocalHost();
                } catch (UnknownHostException var4) {
                    var4.printStackTrace();
                }

                ipAddress = inet.getHostAddress();
            }
        }

        if (ipAddress != null && ipAddress.length() > 15 && ipAddress.indexOf(",") > 0) {
            ipAddress = ipAddress.substring(0, ipAddress.indexOf(","));
        }

        return "0:0:0:0:0:0:0:1".equals(ipAddress) ? "127.0.0.1" : ipAddress;
    }

    public static String getDomain() {
        HttpServletRequest request = SpringUtil.getRequest();
        String path = request.getContextPath();
        String name = request.getServerName();
        StringBuilder serverName = new StringBuilder();
        serverName.append(name);
        if (request.getServerPort() == 80) {
            serverName.append(path);
        } else {
            serverName.append(":").append(request.getServerPort()).append(path);
        }

        String currentDomain = serverName.toString();
        return currentDomain;
    }

    public static void startPage() {
        int pageNo = getInt("pageNo", 1);
        int pageNumber = getInt("pageNumber", 1);
        int _pageNo = pageNo;
        if (pageNumber > pageNo) {
            _pageNo = pageNumber;
        }

        PageHelper.startPage(_pageNo, getInt("pageSize", 10));
    }

    public static int getPageSize() {
        return getInt("pageSize", 10);
    }

    public static int getPageNo() {
        return getInt("pageNo", 1);
    }

    public static void startPage(boolean count) {
        startPage(getInt("pageNo", 1), getInt("pageSize", 10), count);
    }

    public static void startPage(int pageNo, int pageSize, boolean count) {
        PageHelper.startPage(getInt("pageNo", pageNo), getInt("pageSize", pageSize), count);
    }

    public static void orderBy(String orderBy, String order) {
        if (!order.equalsIgnoreCase("DESC") && !order.equalsIgnoreCase("ASC")) {
            order = "DESC";
        }

        PageHelper.orderBy(orderBy + " " + order);
    }

    public static PageInfo endPage(List list, String name) {
        PageInfo page = new PageInfo(list);
        SpringUtil.getRequest().setAttribute("params", assemblyRequestUrlParams(new String[]{"pageNo"}));
        SpringUtil.getRequest().setAttribute(name, page);
        return page;
    }

    public static PageInfo endPage(List list) {
        return endPage(list, "page");
    }

    public static Boolean getBoolean(String param) {
        String value = SpringUtil.getRequest().getParameter(param);

        try {
            return Boolean.parseBoolean(value);
        } catch (Exception var3) {
            return false;
        }
    }

    public static Boolean getBoolean(String param, Boolean def) {
        String value = SpringUtil.getRequest().getParameter(param);
        if (StringUtils.isBlank(value)) {
            return def;
        } else {
            try {
                return Boolean.parseBoolean(value);
            } catch (Exception var4) {
                return def;
            }
        }
    }

    public static Integer getInt(String param, int def) {
        String value = SpringUtil.getRequest().getParameter(param);
        return NumberUtils.isNumber(value) ? Integer.parseInt(value) : def;
    }

    public static Integer getInt(String param) {
        return getInt(param, 0);
    }

    public static String getString(String param, String def) {
        String value = SpringUtil.getRequest().getParameter(param);
        if (StringUtils.isEmpty(value)) {
            value = def;
        }

        return value;
    }

    public static String getString(String param) {
        return getString(param, "");
    }

    public static int[] getInts(String param) {
        String[] value = SpringUtil.getRequest().getParameterValues(param);
        if (ArrayUtils.isNotEmpty(value)) {
            try {
                return StringUtil.stringsToInts(value);
            } catch (NumberFormatException var3) {
                return null;
            }
        } else {
            return null;
        }
    }

    public static int[] getInts(String param, String split) {
        if (getInts(param) != null) {
            return getInts(param);
        } else {
            String value = SpringUtil.getRequest().getParameter(param);
            if (StringUtils.isEmpty(value)) {
                return null;
            } else {
                return ArrayUtils.isNotEmpty(value.split(split)) ? StringUtil.stringsToInts(value.split(split)) : null;
            }
        }
    }

    public static int[] getIds() {
        return getInts("ids");
    }

    public static Map<String, Object> assemblyRequestMap() {
        HttpServletRequest request = SpringUtil.getRequest();
        Map<String, Object> params = new HashMap();
        Map<String, String[]> map = request.getParameterMap();
        Iterator key = map.keySet().iterator();

        while(key.hasNext()) {
            String k = ((String)key.next()).replace(".", "_");
            String[] value = null;
            if (!StringUtil.isBlank(map.get(k))) {
                try {
                    value = (String[])map.get(k);
                } catch (ClassCastException var7) {
                    value = new String[]{map.get(k) + ""};
                }
            }

            if (value == null) {
                params.put(k, (Object)null);
                request.setAttribute(k, (Object)null);
            } else if (value.length == 1) {
                String temp = null;
                if (!StringUtils.isEmpty(value[0])) {
                    temp = value[0];
                }

                params.put(k, temp);
                request.setAttribute(k, temp);
            } else if (value.length == 0) {
                params.put(k, (Object)null);
                request.setAttribute(k, (Object)null);
            } else if (value.length > 1) {
                params.put(k, value);
                request.setAttribute(k, value);
            }
        }

        return params;
    }

    public static String assemblyRequestUrlParams() {
        return assemblyRequestUrlParams((String[])null);
    }

    public static String assemblyRequestUrlParams(String[] filter) {
        Map<String, String[]> map = SpringUtil.getRequest().getParameterMap();
        Iterator<String> key = map.keySet().iterator();
        StringBuffer sb = new StringBuffer();

        while(true) {
            String k;
            do {
                if (!key.hasNext()) {
                    if (sb.length() > 0) {
                        return sb.substring(0, sb.length() - 1);
                    }

                    return sb.toString();
                }

                k = (String)key.next();
            } while(filter != null && Arrays.asList(filter).contains(k));

            if (!StringUtil.isBlank(map.get(k))) {
                String[] value = null;

                try {
                    value = (String[])map.get(k);
                } catch (ClassCastException var7) {
                    value = new String[]{map.get(k) + ""};
                }

                if (value.length == 1) {
                    String temp = "";
                    if (!StringUtils.isEmpty(value[0])) {
                        temp = value[0];
                    }

                    sb.append(k).append("=").append(temp).append("&");
                } else if (value.length > 1) {
                    sb.append(k).append("=").append(value).append("&");
                }
            }
        }
    }

    public static void removeUrlParams(String[] fitlers) {
        SpringUtil.getRequest().setAttribute("params", assemblyRequestUrlParams(fitlers));
    }

    public static Object getSession(BaseSessionEnum key) {
        return SpringUtil.getRequest().getSession().getAttribute(key.toString());
    }

    public static Object getSession(String key) {
        return SpringUtil.getRequest() == null ? null : SpringUtil.getRequest().getSession().getAttribute(key);
    }

    public static void setSession(BaseSessionEnum key, Object value) {
        SpringUtil.getRequest().getSession().setAttribute(key.toString(), value);
    }

    public static void setSession(String key, Object value) {
        SpringUtil.getRequest().getSession().setAttribute(key, value);
    }

    public static void removeSession(BaseSessionEnum key) {
        SpringUtil.getRequest().getSession().removeAttribute(key.toString());
    }

    public static void removeSession(String key) {
        SpringUtil.getRequest().getSession().removeAttribute(key);
    }

    public static String getRealPath(String filePath) {
        if (filePath == null || !filePath.contains("../") && !filePath.contains("..\\")) {
            LOG.debug("filePath {}", filePath);
            String classPath = getClassPath(filePath);
            LOG.debug("classPath {}", classPath);
            if (classPath.startsWith("file")) {
                String path = System.getProperty("user.dir");
                if (StringUtils.isNotBlank(filePath)) {
                    path = path + File.separator + filePath;
                }

                return path;
            } else {
                ServletContext servlet = (ServletContext)SpringUtil.getBean(ServletContext.class);
                LOG.debug("servlet {}", servlet);
                String path = servlet.getRealPath(File.separator);
                LOG.debug("path {}", path);
                if (!StringUtils.isEmpty(filePath)) {
                    String last = path.charAt(path.length() - 1) + "";
                    String frist = filePath.charAt(0) + "";
                    if (last.equals(File.separator)) {
                        if (!frist.equals("\\") && !frist.equals("/")) {
                            path = path + filePath;
                        } else {
                            path = path + filePath.substring(1);
                        }
                    } else if (!frist.equals("\\") && !frist.equals("/")) {
                        path = path + File.separator + filePath;
                    } else {
                        path = path + filePath;
                    }
                }

                return path;
            }
        } else {
            throw new BusinessException("非法路径!");
        }
    }

    public static String getRealTemplatePath(String filePath) {
        String path = null;
        String uploadTemplatePath = MSProperties.upload.template;
        if ((new File(uploadTemplatePath)).isAbsolute()) {
            String os = System.getProperty("os.name");
            String last = uploadTemplatePath.charAt(uploadTemplatePath.length() - 1) + "";
            String frist = filePath.charAt(0) + "";
            if ("\\".equals(frist) && "/".equals(frist)) {
                if ("\\".equals(last) || "/".equals(last)) {
                    uploadTemplatePath = uploadTemplatePath.substring(0, uploadTemplatePath.length() - 1);
                }
            } else if (!"\\".equals(last) || !"/".equals(last)) {
                uploadTemplatePath = uploadTemplatePath + "/";
            }

            path = uploadTemplatePath + filePath;
            if (os.toLowerCase().startsWith("win")) {
                return path.replace("/", "\\");
            }
        } else {
            path = getRealPath(filePath);
        }

        return path;
    }

    public static String getClassPath(String filePath) {
        String os = System.getProperty("os.name");
        String temp = null;

        try {
            temp = ClassUtils.getDefaultClassLoader().getResource("").getPath();
        } catch (Exception var4) {
            var4.printStackTrace();
        }

        return os.toLowerCase().startsWith("win") ? temp.replace("/", "\\") : temp;
    }

    public static Field[] getAllFields(Object object) {
        Class clazz = object.getClass();

        ArrayList fieldList;
        for(fieldList = new ArrayList(); clazz != null; clazz = clazz.getSuperclass()) {
            fieldList.addAll(new ArrayList(Arrays.asList(clazz.getDeclaredFields())));
        }

        Field[] fields = new Field[fieldList.size()];
        fieldList.toArray(fields);
        return fields;
    }

    public static void setValue(Object target, String fieldName, Object value) {
        Class<?> clazz = target.getClass();
        String[] fs = fieldName.split("\\.");

        try {
            for(int i = 0; i < fs.length - 1; ++i) {
                Field f = clazz.getDeclaredField(fs[i]);
                f.setAccessible(true);
                Object val = f.get(target);
                if (val == null) {
                    Constructor<?> c = f.getType().getDeclaredConstructor();
                    c.setAccessible(true);
                    val = c.newInstance();
                    f.set(target, val);
                }

                target = val;
                clazz = val.getClass();
            }

            Field f = clazz.getDeclaredField(fs[fs.length - 1]);
            f.setAccessible(true);
            f.set(target, value);
        } catch (Exception var9) {
            throw new RuntimeException(var9);
        }
    }

    public static Map enumToMap(BaseEnum[] baseEnum) {
        return enumToMap(baseEnum, true);
    }

    public static Map enumToMap(BaseEnum[] baseEnum, boolean idKey) {
        Map map = new HashMap();
        BaseEnum[] var3 = baseEnum;
        int var4 = baseEnum.length;

        for(int var5 = 0; var5 < var4; ++var5) {
            BaseEnum be = var3[var5];
            if (idKey) {
                map.put(be.toInt() + "", be.toString());
            } else {
                Enum e = (Enum)be;
                map.put(e.name(), be.toString());
            }
        }

        return map;
    }

    public static Map resToMap(String resPath) {
        return resToMap(ResourceBundle.getBundle(resPath));
    }

    public static Map resToMap(ResourceBundle rb) {
        Map map = new HashMap();
        Enumeration e = rb.getKeys();

        while(e.hasMoreElements()) {
            String key = e.nextElement().toString();
            map.put(key, rb.getString(key));
        }

        return map;
    }

    public static String getCookie(BaseCookieEnum key) {
        HttpServletRequest request = SpringUtil.getRequest();
        if (request.getCookies() != null) {
            Cookie[] var2 = request.getCookies();
            int var3 = var2.length;

            for(int var4 = 0; var4 < var3; ++var4) {
                Cookie c = var2[var4];
                if (c.getName().equals(key.toString())) {
                    return c.getValue();
                }
            }
        }

        return null;
    }

    public static String getCookie(String key) {
        HttpServletRequest request = SpringUtil.getRequest();
        if (request.getCookies() != null) {
            Cookie[] var2 = request.getCookies();
            int var3 = var2.length;

            for(int var4 = 0; var4 < var3; ++var4) {
                Cookie c = var2[var4];
                if (c.getName().equals(key)) {
                    return c.getValue();
                }
            }
        }

        return null;
    }

    public static void setCookie(HttpServletResponse response, BaseCookieEnum key, Object value) {
        if (value == null) {
            setCookie(response, (String)null, "/", key.toString(), (String)null, -1);
        } else {
            setCookie(response, (String)null, "/", key.toString(), value.toString(), -1);
        }

    }

    public static ManagerEntity getManager() {
        Subject subject = SecurityUtils.getSubject();
        return subject.getPrincipal() instanceof ManagerEntity ? (ManagerEntity)subject.getPrincipal() : null;
    }

    public static void setCookie(HttpServletResponse response, BaseCookieEnum key, Object value, int expiry) {
        setCookie(response, (String)null, "/", key.toString(), value.toString(), expiry);
    }

    public static void setCookie(HttpServletResponse response, String key, String value, int expiry) {
        setCookie(response, (String)null, "/", key.toString(), value.toString(), expiry);
    }

    public static void setCookie(HttpServletResponse response, String domain, String key, String value, int expiry) {
        setCookie(response, domain, "/", key.toString(), value.toString(), expiry);
    }

    public static void setCookie(HttpServletResponse response, String domain, String path, String key, String value, int expiry) {
        if (!StringUtils.isEmpty(key)) {
            Cookie cookie = new Cookie(key.toString(), value);
            if (StringUtils.isNotEmpty(path)) {
                cookie.setPath(path);
            }

            if (StringUtils.isNotEmpty(domain)) {
                cookie.setDomain(domain);
            }

            cookie.setMaxAge(expiry);
            cookie.setHttpOnly(true);
            response.addCookie(cookie);
        }
    }

    public static boolean isMobileDevice() {
        HttpServletRequest request = SpringUtil.getRequest();
        boolean b = false;
        boolean pcFlag = false;
        boolean mobileFlag = false;
        String via = request.getHeader("Via");
        String userAgent = request.getHeader("user-agent");

        int i;
        for(i = 0; via != null && !via.trim().equals("") && i < mobileGateWayHeaders.length; ++i) {
            if (via.contains(mobileGateWayHeaders[i])) {
                mobileFlag = true;
                break;
            }
        }

        for(i = 0; !mobileFlag && userAgent != null && !userAgent.trim().equals("") && i < mobileUserAgents.length; ++i) {
            if (userAgent.contains(mobileUserAgents[i])) {
                mobileFlag = true;
                break;
            }
        }

        for(i = 0; userAgent != null && !userAgent.trim().equals("") && i < pcHeaders.length; ++i) {
            if (userAgent.contains(pcHeaders[i])) {
                pcFlag = true;
                break;
            }
        }

        if (mobileFlag && !pcFlag) {
            b = true;
        }

        return b;
    }

    public static boolean isWechatBrowser() {
        HttpServletRequest request = SpringUtil.getRequest();
        boolean isWechatBrowser = false;
        String ua = request.getHeader("user-agent").toLowerCase();
        if (ua.indexOf("micromessenger") > 0) {
            isWechatBrowser = true;
        }

        return isWechatBrowser;
    }

    public static boolean isAjaxRequest(HttpServletRequest request) {
        return request.getHeader("accept") != null && request.getHeader("accept").equals("*/*") || request.getHeader("X-Requested-With") != null && request.getHeader("X-Requested-With").indexOf("XMLHttpRequest") > -1;
    }

    public static <T> T filter(T obj, final String... filters) {
        if (obj == null) {
            return null;
        } else {
            final List list = Arrays.asList(filters);
            String str = JSONUtil.parseObj(obj).setDateFormat("yyyy-MM-dd HH:mm:ss").toJSONString(0, new Filter<MutablePair<Object, Object>>() {
                public boolean accept(MutablePair<Object, Object> objectObjectMutablePair) {
                    return !list.contains(objectObjectMutablePair.getKey());
                }
            });
            return (T) JSONUtil.toBean(str, obj.getClass());
        }
    }

    public static void outString(HttpServletResponse response, String dataStr) {
        try {
            response.setContentType("text/html;charset=utf-8");
            PrintWriter out = response.getWriter();
            out.print(dataStr);
            out.flush();
            out.close();
        } catch (IOException var3) {
            var3.printStackTrace();
        }

    }

    public static String getMimeType(InputStream fileInput, String fileName) {
        AutoDetectParser parser = new AutoDetectParser();
        parser.setParsers(new HashMap());
        Metadata metadata = new Metadata();
        String fileType = FileNameUtil.extName(fileName);

        try {
            parser.parse(fileInput, new DefaultHandler(), metadata, new ParseContext());
        } catch (ZeroByteFileException var6) {
            return fileType;
        } catch (Exception var7) {
            var7.getStackTrace();
        }

        String contentType = metadata.get("Content-Type");
        if (contentType.contains("/")) {
            fileType = contentType.substring(contentType.lastIndexOf("/") + 1);
        }

        return fileType.contains("-") ? fileType.substring(fileType.lastIndexOf("-") + 1) : fileType;
    }

    public static String getRequestUrl(HttpServletRequest request) {
        StringBuffer requestURL = request.getRequestURL();
        Map<String, String[]> map = request.getParameterMap();
        return requestURL.append(CollectionUtil.isNotEmpty(map) ? "?" + HttpUtil.toParams(map) : "") + "";
    }
}
